package com.sinopec.android;

import com.sinopec.android.util.LogUtil;
import com.sinopec.android.util.StringUtil;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.TextView;

/**
* @ClassName: NoticeDetailActivity
* @Description: TODO(通知详情)
* @author liuwei
* @date 2012-3-31 下午04:46:49
* 
*/
public class NoticeDetailActivity extends BaseActivity {
	private String url = null;
	WebView webview; 
	private ProgressBar progressBar;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.notice_detail_view);
		url = getIntent().getExtras().getString("url");
		initView();
		LogUtil.printInfo("url:"+url);
		if(StringUtil.isNotEmpty(url)){
			webview.loadUrl(url);
			webview.setWebViewClient(new WebClient());

		}
	}
	
	void initView(){
		((TextView)findViewById(R.id.navi)).setText("通知");
		webview = (WebView) findViewById(R.id.webview);
		progressBar = (ProgressBar) findViewById(R.id.progress_bar);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setBuiltInZoomControls(true);
        
        webview.getSettings().setSupportZoom(true); 
        webview.setInitialScale(10); //为25%，最小缩放等级 ，可以在这里根据需求来设置缩放比例. 
       
	}
	
	  private class WebClient extends WebViewClient{

			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				view.loadUrl(url);
				return true;
			}

			@Override
			public void onPageFinished(WebView view, String url) {
				// TODO Auto-generated method stub
				super.onPageFinished(view, url);
				progressBar.setVisibility(View.GONE);
				
			}
			
	    	
	    }
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if(keyCode == KeyEvent.KEYCODE_BACK){
			Intent it = new Intent();
			it.setClass(NoticeDetailActivity.this, NoticeListActivity.class);
			startActivity(it);
			NoticeDetailActivity.this.finish();
			return false;
		}
		return super.onKeyDown(keyCode, event);
	}
}
